#include "antlr4-runtime.h"
#include <iostream>
#include "NasmLexer.h"
#include "NasmParser.h"
#include "nasm/visitor/symbolCollector.h"
#include "nasm/visitor/instGenerator.h"

int main(int argc, char *argv[]) {
    std::ifstream stream;
    stream.open(argv[1]);

    antlr4::ANTLRInputStream input(stream);
    dspnasm::NasmLexer lexer(&input);
    antlr4::CommonTokenStream tokens(&lexer);
    dspnasm::NasmParser parser(&tokens);
    auto program = parser.program();


    std::shared_ptr<dspnasm::SymbolTable> symbolTable = std::make_shared<dspnasm::SymbolTable>();
    std::shared_ptr<dspnasm::ElfFile> elfFile = std::make_shared<dspnasm::ElfFile>();
    elfFile->m_fileName = "./a";
    auto visitor = std::make_shared<dspnasm::SymbolCollector>(symbolTable,elfFile);
    visitor->visitProgram(program);
    symbolTable->printSymbol();

    auto instGen = std::make_shared<dspnasm::InstGenerator>(symbolTable,elfFile);
    instGen->visitProgram(program);

    symbolTable->exportSymbols(elfFile);
    elfFile->writeElf();
    return 0;
}
